/***************************************************************************
 * The Open Armory API is a project to retrieve World of Warcraft(R) 
 * related XML data from The Armory.
 * 
 * The data retrieved via the Open Armory API from The Armory is 
 * proprietary to Blizzard Entertainment, Inc(R).
 * *************************************************************************
 * Copyright (C) 2009 - 2010 Tedla M.B. Brandsema
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/
package net.openarmory.core.domain;

import java.io.File;
import java.io.InputStream;

import net.openarmory.core.domain.constants.ArmoryCharacterDataType;
import net.openarmory.core.domain.constants.ArmoryZone;

/**
 * The Class {@code ArmoryCharacterXmlWriter} writes the XML data retrieved via
 * the {@link ArmoryCharacterXmlRetriever} to disk.
 */
public final class ArmoryCharacterXmlWriter extends ArmoryXmlWriter {

	/** The character XML retriever. */
	private final ArmoryCharacterXmlRetriever characterXmlRetriever = new ArmoryCharacterXmlRetriever();

	/**
	 * Writes character XML to disk.
	 * 
	 * @param zone
	 *            The zone represents The Armory region (i.e. EU or US).
	 * @param realm
	 *            The realm on which the character resides on.
	 * @param characterName
	 *            The character name.
	 * @param armoryCharacterDataType
	 *            The armory character data type.
	 */
	public void writeCharacterXml(final ArmoryZone zone, final String realm,
			final String characterName,
			final ArmoryCharacterDataType armoryCharacterDataType) {
		final InputStream characterXmlInputStream = this.characterXmlRetriever
				.fetchCharacterXml(zone, realm, characterName,
						armoryCharacterDataType);
		final String outFilename = armoryCharacterDataType
				.getUrlConfigProperty();
		final File outFile = createOutFile(outFilename, zone, realm,
				characterName, true);
		writeXmlFile(characterXmlInputStream, outFile);
	}
}
